package br.com.sistema.dao;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import br.com.sistema.conexao.Entity;
import br.com.sistema.models.Cep;

public class CepDao implements IDao<Cep> {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<Cep> obterPorCodigo(String codigo) throws Exception {
		
		try{
			
			EntityManager em = Entity.createEm();
			List<Cep> list;
			
			try {
				
				CriteriaBuilder cb = em.getCriteriaBuilder();
				CriteriaQuery c = cb.createQuery(Cep.class);
				Root<Cep> a = c.from(Cep.class);
				c.select(a);
				List<Predicate> predicates = new ArrayList<Predicate>();
				predicates.add(cb.equal(a.<String>get("cepcodigo"), codigo));
				c.where(cb.and(predicates.toArray(new Predicate[]{})));
				TypedQuery<Cep> query = em.createQuery(c);
				list = query.getResultList();
				
				return list;
				
			} catch (Exception e) {
				
				throw e;
				
			} finally{
				
				em.close();

			}
			
		}catch(Exception e){
			
			throw e;
		}
	}
	
	@Override
	public Cep getById(int id) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Cep> getByCriteria(Cep o) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void remove(List<Cep> list) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Cep> getAll() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Cep manter(Cep o) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Cep insere(Cep o) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Cep altera(Cep o) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}


}
